package cz.zcu.fav.rat.managed.bean.calendar.event;

import cz.zcu.fav.rat.beans.Period;
import cz.zcu.fav.rat.beans.User;
import cz.zcu.fav.rat.managed.bean.calendar.ReservationEvent;

public class UserSpecificReservationFactory implements IEventFactory
{
	private static final long serialVersionUID = 3627019826026705192L;
	User user;

	public UserSpecificReservationFactory(User user)
	{
		this.user = user;
	}

	@Override
	public ReservationEvent getEvent(Period period)
	{

		ReservationEvent event = new ReservationEvent(period.getReservation()
				.getObject().getName(), period.getFromDate().toDate(),
				period.getToDate().toDate(), period.getReservation().getUser(),
				period.getReservation().getObject(), period.getReservation(),
				period)
		{
			private static final long serialVersionUID = 2476694502395749726L;

			@Override
			public String getStyleClass()
			{

				if (!getUser().equals(user))
				{
					return StyleClass.GREY.toString();
				} else
				{
					return StyleClass.GREEN.toString();
				}
			}

			@Override
			public boolean isEditable()
			{
				if (!getUser().equals(user))
				{
					return false;
				} else
				{
					return super.isEditable();
				}

			}

			@Override
			public boolean isDeletable()
			{
				if (!getUser().equals(user))
				{
					return false;
				} else
				{
					return super.isDeletable();
				}
			}

			@Override
			public boolean isPickable()
			{
				if (!getUser().equals(user))
				{
					return false;
				} else
				{
					return super.isPickable();
				}
			}

			@Override
			public boolean isReturnable()
			{
				if (!getUser().equals(user))
				{
					return false;
				} else
				{
					return super.isReturnable();
				}
			}
		};
		event.setEnabled(period.isValid());
		event.setPeriodical(period.getReservation().getPeriods().size() > 1);
		return event;
	}
}
